﻿using System;
using UnityEngine;
using UnityEngine.UI;

public class VisitorItem : UserIconItem
{
    public GameObject newSign;
    public Text visitTimeText;
    public Text genderText;
    Visit m_Data;
    public Visit data => m_Data;
    Action<VisitorItem> m_onSelectVisitorItem;
    public void Init(Visit visit, Action<VisitorItem> onSelectVisitorItem)
    {
        m_Data = visit; 
        m_onSelectVisitorItem = onSelectVisitorItem;

        base.Init(visit.name, visit.birthYear, visit.locationCity, visit.height, visit.iconTex);

        this.visitTimeText.text = $"{UnityFunctions.GetTimeElapsed(visit.lastVisitTime)}前，共{visit.totalVisitCount}次";
        genderText.text = visit.gender == Gender.woman ? "女" : "男";
        newSign.SetActive(false);
    }
    void OnEnable()
    {
        StartCoroutine(UnityFunctions.AdjustItemsLayout(transform));
    }
    public void OnClick()
    {
        m_onSelectVisitorItem?.Invoke(this);
    }
}
